﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Search for places that can be attached to a statuses/update.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.GeoToolbox.bmp")]
    [Designer(typeof(SearchGeoPlacesDesigner))]
    [Description("Search for places that can be attached to a statuses/update.")]
    public class SearchGeoPlaces : TwitterOperationInvoker<GeoSearchResult>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchGeoPlaces"/> class.
        /// </summary>
        public SearchGeoPlaces()
            : base("SearchGeo")
        {
            MaxResults = new InArgument<int>(new CSharpValue<int>("20"));
        }

        /// <summary>
        /// The latitude to search around.
        /// </summary>
        /// <value>
        /// The latitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The latitude to search around.")]
        public InArgument<string> Latitude { get; set; }

        /// <summary>
        /// The longitude to search around. 
        /// </summary>
        /// <value>
        /// The longitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The longitude to search around. ")]
        public InArgument<string> Longitude { get; set; }

        /// <summary>
        /// Free-form text to match against while executing a geo-based query
        /// </summary>
        /// <value>
        /// The query.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Free-form text to match against while executing a geo-based query")]
        public InArgument<string> Query { get; set; }

        /// <summary>
        /// An IP address. Used when attempting to fix geolocation based off of the user's IP address.
        /// </summary>
        /// <value>
        /// The IP.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("An IP address.")]
        public InArgument<string> IP { get; set; }

        /// <summary>
        /// This is the minimal granularity of place types to return and must be one of: poi, neighborhood, city, admin or country.
        /// </summary>
        /// <value>
        /// The granularity.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("This is the minimal granularity of place types to return and must be one of: poi, neighborhood, city, admin or country.")]
        public InArgument<string> Granularity { get; set; }

        /// <summary>
        /// A hint on the region in which to search. 
        /// Example Values: 5ft
        /// </summary>
        /// <value>
        /// The accuracy.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("A hint on the region in which to search. Example Values: 5ft")]
        public InArgument<string> Accuracy { get; set; }

        /// <summary>
        /// This is the place_id which you would like to restrict the search results to.
        /// </summary>
        /// <value>
        /// The contained within.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("This is the place_id which you would like to restrict the search results to.")]
        public InArgument<string> ContainedWithin { get; set; }

        /// <summary>
        /// This parameter searches for places which have this given street address.
        /// </summary>
        /// <value>
        /// The street address.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("This parameter searches for places which have this given street address.")]
        public InArgument<string> StreetAddress { get; set; }

        /// <summary>
        /// A hint as to the number of results to return. 
        /// </summary>
        /// <value>
        /// The max results.
        /// </value>
        [Browsable(true)]
        [Category("Navigation")]
        [Description("A hint as to the number of results to return. ")]
        public InArgument<int> MaxResults { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument latitudeArgument = new RuntimeArgument("Latitude", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Latitude, latitudeArgument);
            metadata.AddArgument(latitudeArgument);

            RuntimeArgument longitudeArgument = new RuntimeArgument("Longitude", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Longitude, longitudeArgument);
            metadata.AddArgument(latitudeArgument);

            RuntimeArgument queryArgument = new RuntimeArgument("Query", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Query, queryArgument);
            metadata.AddArgument(queryArgument);

            RuntimeArgument ipArgument = new RuntimeArgument("IP", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(IP, ipArgument);
            metadata.AddArgument(ipArgument);

            RuntimeArgument granularityArgument = new RuntimeArgument("Granularity", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Granularity, granularityArgument);
            metadata.AddArgument(granularityArgument);

            RuntimeArgument accuracyArgument = new RuntimeArgument("Accuracy", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Accuracy, accuracyArgument);
            metadata.AddArgument(accuracyArgument);

            RuntimeArgument containedWithinArgument = new RuntimeArgument("ContainedWithin", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(ContainedWithin, containedWithinArgument);
            metadata.AddArgument(containedWithinArgument);

            RuntimeArgument streetAddressArgument = new RuntimeArgument("StreetAddress", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(StreetAddress, streetAddressArgument);
            metadata.AddArgument(streetAddressArgument);

            RuntimeArgument maxResultsArgument = new RuntimeArgument("MaxResults", typeof(int), ArgumentDirection.In, false);
            metadata.Bind(MaxResults, maxResultsArgument);
            metadata.AddArgument(maxResultsArgument);


            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("latitude", Latitude);
            Parameters.Add("longitude", Longitude);
            Parameters.Add("query", Query);
            Parameters.Add("ip", IP);
            Parameters.Add("granularity", Granularity);
            Parameters.Add("accuracy", Accuracy);
            Parameters.Add("containedWithin", ContainedWithin);
            Parameters.Add("streetAddress", StreetAddress);
            Parameters.Add("maxResults", MaxResults);

            base.Execute(context);
        }

    }
}
